package com.ruoyi.web.controller.system.app;

import java.util.List;

import com.ruoyi.common.utils.UtilTool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AppAbout;
import com.ruoyi.system.service.IAppAboutService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * app说明Controller
 * 
 * @author ruoyi
 * @date 2021-07-30
 */
@Controller
@RequestMapping("/system/about")
public class AppAboutController extends BaseController
{
    private String prefix = "system/about";

    @Autowired
    private IAppAboutService appAboutService;

    /**
     * 查询app说明列表
     */
    @PostMapping("/list")
    @ResponseBody
    public AjaxResult list(AppAbout appAbout)
    {
        AppAbout about = appAboutService.selectAppAboutById(1l);
        return AjaxResult.success(about);
    }

    /**
     * 导出app说明列表
     */
    @Log(title = "app说明", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AppAbout appAbout)
    {
        List<AppAbout> list = appAboutService.selectAppAboutList(appAbout);
        ExcelUtil<AppAbout> util = new ExcelUtil<AppAbout>(AppAbout.class);
        return util.exportExcel(list, "app说明数据");
    }

    /**
     * 新增保存app说明
     */
    @Log(title = "app说明", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AppAbout appAbout)
    {
        return toAjax(appAboutService.insertAppAbout(appAbout));
    }

    /**
     * 修改保存app说明
     */
    @Log(title = "app说明", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AppAbout appAbout)
    {
        AppAbout about = appAboutService.selectAppAboutById(1l);
        if (UtilTool.isNull(about)){
            about = new AppAbout();
            about.setLogoUrl(appAbout.getLogoUrl());
            about.setName(appAbout.getName());
            return toAjax(appAboutService.insertAppAbout(about));
        }else {
            appAbout.setId(1l);
            return toAjax(appAboutService.updateAppAbout(appAbout));
        }
    }

    /**
     * 删除app说明
     */
    @Log(title = "app说明", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(appAboutService.deleteAppAboutByIds(ids));
    }
}
